package com.siyu.controller;

import com.siyu.model.Files;
import com.siyu.service.FileService;
import com.siyu.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    private UserService userService;

    @Autowired
    private FileService fileService;

    // 禁用用户
    @PostMapping("/disableUser/{userId}")
    public ResponseEntity<String> disableUser(@PathVariable Long userId) {
        userService.disableUser(userId);
        return ResponseEntity.ok("User disabled successfully");
    }

    // 修改用户角色
    @PostMapping("/changeRole/{userId}")
    public ResponseEntity<String> changeUserRole(@PathVariable Long userId, @RequestParam String role) {
        userService.changeUserRole(userId, role);
        return ResponseEntity.ok("User role changed successfully");
    }

    // 获取所有共享文件
    @GetMapping("/sharedFiles/{userId}")
    public List<Files> getSharedFiles(@PathVariable Long userId) {
        return fileService.getSharedFiles(userId);
    }
}